class GRs:
    def __init__(self):
        self.gr = [0 for i in range(16)]
    def reset(self):
        for i in range(16):
            self.gr[i] = 0
                    
    def write_gr64(self, value, un):
        self.gr[un] = value & 0xFFFFFFFFFFFFFFFF;
        
    def write_gr32(self, value, vn):
        if vn & 1 == 1:
            self.gr[vn >> 1] = (self.gr[vn >> 1] & 0xFFFFFFFF) | ( (value << 32) & 0xFFFFFFFF00000000)
        else:
            self.gr[vn >> 1] = (self.gr[vn >> 1] & 0xFFFFFFFF00000000) | ( (value) & 0xFFFFFFFF)
                    
    def write_gr16(self, value, wn):
        if wn & 3 == 0:
            self.gr[wn >> 2] = (self.gr[wn >> 2] & 0xFFFFFFFFFFFF0000) | ( (value) & 0xFFFF)
        elif wn & 3 == 1:
            self.gr[wn >> 2] = (self.gr[wn >> 2] & 0xFFFFFFFF0000FFFF) | ( (value << 16) & 0xFFFF0000)
        elif wn & 3 == 2:
            self.gr[wn >> 2] = (self.gr[wn >> 2] & 0xFFFF0000FFFFFFFF) | ( (value << 32) & 0xFFFF00000000)
        elif wn & 3 == 3:
            self.gr[wn >> 2] = (self.gr[wn >> 2] & 0x0000FFFFFFFFFFFF) | ( (value << 48) & 0xFFFF000000000000)
            
    def read_gr64(self, un):
        return self.gr[un]
    
    def read_gr32(self, vn):
        if vn & 1 == 0:
            return self.gr[(vn >> 1)] & 0xFFFFFFFF
        else:
            return (self.gr[(vn >> 1)] >> 32) & 0xFFFFFFFF
        
    def read_gr16(self, wn):
        if wn & 3 == 0:
            return (self.gr[wn >> 2]) & 0xFFFF
        elif wn & 3 == 1:
            return (self.gr[wn >> 2] >> 16) & 0xFFFF
        elif wn & 3 == 2:
            return (self.gr[wn >> 2] >> 32) & 0xFFFF
        elif wn & 3 == 3: 
            return (self.gr[wn >> 2] >> 48) & 0xFFFF
        
    def list_all(self):
        print "------------------------------"
        for i in range(15, -1, -1):
            print "%4X\t%04X_%04X_%04X_%04X" % (i, self.read_gr16(i * 4 + 3), self.read_gr16(i * 4 + 2), self.read_gr16(i * 4 + 1), self.read_gr16(i * 4))
        print "------------------------------"